package com.larry.spark.rdd.transform

import org.apache.spark.{SparkConf, SparkContext}

object RDD_Oper_MapPartitionsWithIndex {

  def main(args: Array[String]): Unit = {
    //TODO  使用spark

    val conf = new SparkConf().setMaster("local[*]").setAppName("rdd")
    val sc = new SparkContext(conf)

    val rdd = sc.makeRDD(List(1, 2, 3, 4, 5, 6),3)

    val rdd1 = rdd.mapPartitionsWithIndex(
      (index, list) => {
        if (index == 1) {
          list
        } else {
          Nil.iterator
        }
      }
    )

    rdd1.collect().foreach(println)

    sc.stop()
  }


}
